<?php

namespace app\admin\controller;

use think\Db;
class Node extends AdminController
{
    public function select()
    {
        $list = Db::name('node')->order('id', 'desc')->paginate(6);
//        dump($list);exit;
        return view('admin@node/index',['list'=>$list]);
    }

    public function add()
    {
        return view('admin@node/add');
    }

    public function doadd()
    {

//        dump(input('post.'));exit;
//        $p = $request->post();
        // $p = Request::instance()->post();
        // $p = input('post.');
//        var_dump($p);

//        dump(input('post.'));exit;
        $data = [
            'name' => input('post.name'),
            'status' => input('post.status'),
            'mname' => input('post.mname'),
            'aname' => input('post.aname')

        ];

        var_dump($data);
        $result = Db::name('node')->data($data)->insert();

        if ($result > 0) {
            return $this->success('添加成功', url('admin/node/select'));
        } else {
            return $this->error('添加失败');
        }


    }

    public function del($id)
    {
        //        dump($_GET);exit;
//        dump(input('get.id'));exit;
        $result = Db::name('node')->delete($id);
        if ($result > 0) {
            return $this->success('删除成功');
        } else {
            return $this->error('删除失败');
        }
    }

    public function update($id)
    {
        $date = Db::name('node')->find($id);
//        dump($date);exit;
        return view('admin@node/update',['date'=> $date]);

    }

    public function doupdate($id)
    {
//        dump(input('post.'));
        $data = [
            'name' => input('post.name'),
            'status' => input('post.status'),
            'mname' => input('post.mname'),
            'aname' => input('post.aname')

        ];

//        dump($data);exit;

        $result = Db::name('node')->where('id',$id)->update($data);

        if ($result) {
            return $this->success('编辑成功',url('admin/node/select'));
        } else {
            return $this->error('编辑失败');
        }


    }
}
